package com.neusoft.dibuy.th;



public class MyThread {

    public static class  Thread2 extends  Thread{
        public void run(){
            String s = Thread.currentThread().getName();
            int times = Integer.parseInt(s);
            for (int i = 0; i <times  ; i++) {
                System.out.println(  Thread.currentThread().getName() + "  : ------------>"+ i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                ;
            }
        }
    }

    public static void main(String[] args) {
        Thread2 thread2 = new Thread2();
        thread2.setName("11");
        thread2.start();
        Thread thread =new Thread(new Thread2());
        thread.setName("22");
        thread.start();
        System.out.println("main end ");
    }


    public static void main5(String[] args) {
        Thread thread1 =new Thread(()->{
            new B().b();
        });
        thread1.setName("111111111111");
        thread1.start();
        Thread thread2 =new Thread(()->{
            new B().b();
        });
        thread2.setName("22");
        thread2.start();
    }
    public static void main4
            (String[] args) {
         Thread t =  new Thread(()->{
             new A().a();
         }) ;
         t.start();
        System.out.println("main end ");
        t.start();
    }

    public static void main3(String[] args) {
        Thread thread =new Thread(new Thread2());
        thread.start();
        for (int i = 0; i <10 ; i++) {
            System.out.println( "main : ------------>"+ i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main2(String[] args) {
        Thread2 thread2 = new Thread2();
        Thread thread =new Thread(thread2);
        thread.start();
        System.out.println("main end ");
    }


    /**
     * 线程的创建
     * TODO : 任何一个进程的 main 方法都必须转变为一个现场 主线程
     * 由主线程去管理其它的工作线程，主线程除了可以管理其它现场之外，再无任何其它特性
     * 线程结束的条件：指令序列执行结束，线程结束；或者被Kill
     * 进程结束：所有的现场都结束
     *
     * @param args
     */
    public static void main1(String[] args) {
/**
 * TODO：实例化线程对象，start启动线程
 */
        Thread thread = new Thread1();
//       对象成为线程
//       克隆run方法
        thread.start();
//        thread.run();
        System.out.println("main end ");
    }
}

/**
 * 为了弥补因线程类已经拥有父类而无法再次继承Thread类的不足，我们可以实现Runnable接口，
 */

class Thread2 extends   Object  implements  Runnable  {
    /**
     * 被克隆的方法
     */
    @Override
    public void run() {
        for (int i = 0; i <10 ; i++) {
            System.out.println(123 + ":------------>"+ i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}


/**
 * TODO：继承Threa类，重写run方法
 */
class  Thread1 extends Thread   {
    /**
     * 被克隆的方法
     */
    public void run() {
        for (int i = 0; i <10 ; i++) {
            System.out.println(123 + ":------------>"+ i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
class  B{
    public void b(){
        for (int i = 0; i <10 ; i++) {
            System.out.println( "thread1 : ------------> : " + Thread.currentThread().getName());
        }
    }
}
class A{
    public void  a(){
        for (int i = 0; i <10 ; i++) {
            System.out.println( "main : ------------>"+ i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}